package org.ushio.nchu_22201406.dao;

import org.apache.ibatis.annotations.*;
import org.ushio.common_module.entity.BusinessInformation;
import java.util.List;

@Mapper
public interface BusinessInformationMapper {

    @Results({
            @Result(property = "phoneNumber", column = "Phone_Number"),
            @Result(property = "packageId", column = "Package_ID"),
            @Result(property = "balance", column = "Balance"),
            @Result(property = "dataBalance", column = "Data_Balance"),
            @Result(property = "callTimeBalance", column = "Call_Time_Balance")
    })
    @Select("SELECT * FROM business_information WHERE Phone_Number = #{phoneNumber}")
    BusinessInformation findBusinessInformationByPhoneNumber(@Param("phoneNumber") String phoneNumber);

    @Select("SELECT Phone_Number, Package_ID, Balance, Data_Balance, Call_Time_Balance FROM business_information")
    @Results({
            @Result(property = "phoneNumber", column = "Phone_Number"),
            @Result(property = "packageId", column = "Package_ID"),
            @Result(property = "balance", column = "Balance"),
            @Result(property = "dataBalance", column = "Data_Balance"),
            @Result(property = "callTimeBalance", column = "Call_Time_Balance")
    })
    List<BusinessInformation> getAllBusinessInformation();

    @Select("SELECT Package_ID, Balance, Data_Balance, Call_Time_Balance FROM business_information WHERE Phone_Number = #{phoneNumber}")
    @Results({
            @Result(property = "packageId", column = "Package_ID"),
            @Result(property = "balance", column = "Balance"),
            @Result(property = "dataBalance", column = "Data_Balance"),
            @Result(property = "callTimeBalance", column = "Call_Time_Balance")
    })
    BusinessInformation getBusinessInformationByPhoneNumber(String phoneNumber);

    @Update("UPDATE business_information SET Package_ID=NULL WHERE Phone_Number = #{phoneNumber}")
    void updatePackageID(@Param("phoneNumber") String phoneNumber);
}
